package com.example.demo.service;

import com.example.demo.mapper.UserMapper;
import com.example.demo.model.User;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @author: 徐飞龙
 * @date: 2024-04-01
 */
@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    @Tool(name = "find_all_users", description = "查询所有用户")
    public List<User> findAll() {
        return userMapper.findAll();
    }

    @Tool(name = "find_by_id", description = "根据id查询用户")
    public User findById(Long id) {
        return userMapper.findById(id);
    }

    @Tool(name = "create_one_user", description = "创建一个用户")
    public int insert(User user) {
        return userMapper.insert(user);
    }

    public int update(User user) {
        return userMapper.update(user);
    }

    public int delete(Long id) {
        return userMapper.delete(id);
    }

    @Tool(name = "get_current_time", description = "获取当前系统时间")
    public String getCurrentTime() {
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return now.format(formatter);
    }
}